import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.util.*;

/**
 * Created by Administrator on 2016/6/3 0003.
 */
public class Maze {
    /*************** 外部接口数据 ***************/
    private MazeJFrame mazeJFrame;
    private MazeAlgorithm mazeAlgorithm;

    /*************** 内部数据 ***************/
    private int testcount;

    public Maze(MazeJFrame mazeJFrame){
        try {
            mazeAlgorithm = new MazeAlgorithm(this);
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.mazeJFrame = mazeJFrame;
        testcount=0;
    }
    public void dataClear(){
        mazeAlgorithm.dataClear();
    }
    public MazeAlgorithm getMazeAlgorithm(){
        return this.mazeAlgorithm;
    }
    public void setHighAndWidth(int width, int high){
        mazeAlgorithm.dataClear();
        this.createMaze(width,high);
    }
    /* 创建指定大小的迷宫 */
    public void createMaze(int width, int high){
        mazeAlgorithm.createMaze(width,high);
    }
    /* 获取迷宫启动的一些参数 */
    public void setMazeStartPara(MazeJFrame mazeJFrame){
        mazeAlgorithm.restoreMazeFace();
        mazeAlgorithm.setAlgorighmPara(mazeJFrame);
    }
    //一个测试函数
    public void drawTest(){
        mazeAlgorithm.getMazePoints()[testcount%5][3].setSteped(true);
        mazeJFrame.getMazeFaceJPanel().refresh();
        testcount++;
    }
    /* 刷新迷宫界面 */
    public void refreshFace(){
        mazeJFrame.getMazeFaceJPanel().refresh();
    }
    /* 迷宫开始启动 */
    public void mazeStart(MazeJFrame mazeJFrame){
        setMazeStartPara(mazeJFrame);
        refreshFace();
        getMazeAlgorithm().mazeStart();
        mazeJFrame.getJBMazeStart().setText("停止");
    }
    public void mazeStop(){
        mazeAlgorithm.mazeStop();
        mazeJFrame.getJBMazeStart().setText("启动迷宫");
    }
}
enum MazeDirection {
    UP,DOWN,LEFT,RIGHT,BUTT
};
class MazePoint{
    private int mazeX;
    private int mazeY;
    private boolean upIsSteped;
    private boolean leftIsSteped;
    private boolean faceIsSteped;
    public void clone(MazePoint otherPoint){
        otherPoint.mazeX = mazeX;
        otherPoint.mazeY = mazeY;
        otherPoint.upIsSteped = upIsSteped;
        otherPoint.leftIsSteped = leftIsSteped;
        otherPoint.faceIsSteped = faceIsSteped;
    }
    public int getMazeX(){
        return this.mazeX;
    }
    public void setMazeX(int x){
        this.mazeX = x;
    }
    public void setMazeY(int y){
        this.mazeY = y;
    }
    public void setLeftSteped(boolean steped){
        this.leftIsSteped = steped;
    }
    public void setUpSteped(boolean steped){
        this.upIsSteped = steped;
    }
    public void setSteped(boolean steped){
        this.faceIsSteped = steped;
    }
    public int getMazeY(){
        return this.mazeY;
    }
    public boolean getSteped(){
        return this.faceIsSteped;
    }
    public boolean isPointCanGo(){
        return this.faceIsSteped^true;
    }
    public boolean getUpSteped(){
        return this.upIsSteped;
    }
    public boolean getLeftSteped(){
        return this.leftIsSteped;
    }
    public MazePoint(){
        this.mazeX = 0;
        this.mazeY = 0;
        this.faceIsSteped = false;
    }
    public MazePoint(int x, int y){
        this.mazeX = x;
        this.mazeY = y;
        this.faceIsSteped = false;
    }
    public void clear(){
        this.upIsSteped     = false;
        this.leftIsSteped   = false;
        this.faceIsSteped   = false;
    }
    public boolean equalsPoint(MazePoint mazePoint){
        if(this.mazeX == mazePoint.getMazeX() && this.mazeY == mazePoint.getMazeY()){
            return true;
        }
        return false;
    }
}

